<template>
  <div>
    <el-tree
      :data="data"
      :props="defaultProps"
      node-key="catId"
      ref="menuTree"
      @node-click="nodeclick"
    >
    </el-tree>
  </div>
</template>

<script>
export default {
//import 引入的组件需要要注入到对象中才能使用
  components: {},
  props: {},
  data() {
//这里存放数据
    return {
      data: [],
      defaultProps: {
        children: 'children',
        label: 'name'
      }
    };
  },
//计算属性
  computed: {},
//监控data中的数据变化
  watch: {},
//方法集合
  methods: {
    nodeclick(data,node,component){
      console.log("子组件被点击",data,node,component)
      //向父组件发送事件
      this.$emit("tree-node-click",data,node,component)
    },
    getMenus() {
      this.dataListLoading = true
      this.$http({
        url: this.$http.adornUrl('/product/category/list/tree'),
        method: 'get',
      }).then(({data}) => {
        if (data && data.code === 0) {
          this.data = data.data
        } else {
          this.data = []
        }
        this.dataListLoading = false
      })
    }
  },
//生命周期-创建完成(可以访问当前this实例)
  created() {
    this.getMenus();
  },
//改在完成,可以方位dom元素
  mounted() {
  },
  beforeCreate() {
  },//创建之前
  beforeMount() {
  },//挂载之前
  beforeDestroy() {
  },
  destroyed() {
  },
  activated() {
  }
};
</script>

<style scoped>

</style>
